package com.thread.thread5;

import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author : leimingchao
 * @date Date : 2021年11月30日 20:38
 */
public class CompletableFutureTest {


    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService threadPool = Executors.newFixedThreadPool(10);
        System.out.println("主线程开始。。。。。。。。");
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程开始：" + Thread.currentThread());
            String s = UUID.randomUUID().toString();
            System.out.println("当前线程结束：" + Thread.currentThread());
            return s;
        }, threadPool).whenComplete((r,e) -> {
            System.out.println("方法执行完后的结果：" + r);
            System.out.println("方法执行完后的异常是：" + e);
        });
        System.out.println("主线程结束。。。。。。。。" + completableFuture.get());
        threadPool.shutdown();
    }
}
